package com.list88zhu.common;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.list88zhu.common.rxhttp.http.HttpClient;
import com.list88zhu.common.rxhttp.http.HttpOnNextListener;
import com.list88zhu.common.rxhttp.http.exception.ApiException;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends RxAppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.GET).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String, String> params = new HashMap<>();
                params.put("city", "上海");
                GetHttpSampleImpl getHttpSample = new GetHttpSampleImpl(new HttpOnNextListener() {
                    @Override
                    public void onNext(String result, String method) {
                        Log.i(TAG, result);
                    }

                    @Override
                    public void onError(ApiException e) {
                        Log.e(TAG, "onError: " + e.getMessage());
                    }
                }, MainActivity.this);
                getHttpSample.setParams(params);
                HttpClient.getInstance().doHttpDeal(getHttpSample);
            }
        });
    }
}
